<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
 
<s:layout-render name="/layout_template.jsp" nadpis="serviceCheck.meinHeading">    
    <s:layout-component name="telo">
        <s:useActionBean beanclass="cz.muni.fi.pa165.carparkweb.actionbeans.ServiceCheckActionBean" var="actionBean"/>
         <table>
            <tr>
                <s:form beanclass="cz.muni.fi.pa165.carparkweb.actionbeans.ServiceCheckActionBean" >
                <td>  
                        <s:select name="vehicleFilter" style="width: 250px">
                            <s:option value="-1" label=""><f:message key="all"/></s:option>
                            <s:options-collection collection="${actionBean.vehicles}" value="id"/>
                        </s:select>
                 </td>
                 <td>
                        <s:select name="doneChecksFilter" style="width: 100px">
                            <s:option value="-1" label="VsetkyX"><f:message key="all"/></s:option>
                            <s:option value="1" label="HotoveX"><f:message key="isDone"/></s:option>
                            <s:option value="0" label="NehotoveX"><f:message key="notDone"/></s:option>
                        </s:select>       
                 </td>
                 <td>
                        <s:select name="activeChecksFilter" style="width: 90px">
                            <s:option value="-1" label=""><f:message key="all"/></s:option>
                            <s:option value="1" label="AktivneX"><f:message key="isActive"/></s:option>
                            <s:option value="0" label="NeaktivneX"><f:message key="notActive"/></s:option>
                        </s:select>
                     <s:submit name="getByFilter"><f:message key="show"/></s:submit>
                 </td>        
                </s:form>
           </tr>
        </table>
        <table id="basicview">
            <thead>
                <tr>
                    <th><f:message key="id"/></th>
                    <th><f:message key="serviceCheck.date"/></th>
                    <th><f:message key="serviceCheck.checkDone"/></th>
                    <th><f:message key="serviceCheck.checkPurpose"/></th>
                    <th><f:message key="serviceCheck.checkInterval"/></th>
                    <th><f:message key="vehicle"/></th>
                    <th><f:message key="serviceCheck.isActive"/></th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${actionBean.checks}" var="servicecheck"> 
                    <jsp:setProperty name="actionBean" property="servicecheck" value="${servicecheck}"/>
                    <tr>
                        <td>${servicecheck.id}</td>
                        <c:if test="${!empty servicecheck.dateOfCheck}">
                            <f:message key="dateFormatForm" var="checkDate" />
                            <f:formatDate value="${servicecheck.dateOfCheck}" pattern="${checkDate}" var="checkdatevar" />
                             <td><c:out value="${checkdatevar}" /></td>
                        </c:if>
                        <c:if test="${empty servicecheck.dateOfCheck}">
                            <td><c:out value="---"/></td>
                        </c:if>
                        <td><f:message key="${servicecheck.checkDone}"/></td>
                        <td><c:out value="${servicecheck.checkPurpose}"/></td>
                        <td><c:out value="${servicecheck.checkInterval}"/></td>
                        <td>
                            <c:if test="${empty actionBean.checkVehicle}"><f:message key="${vehicle.none}"/></c:if>
                            <c:if test="${!empty actionBean.checkVehicle}"> <c:out value="${actionBean.checkVehicle.stateLicencePlate}"/></c:if>
                        </td>
                         <c:if test="${servicecheck.isActive}">
                             <td style="color: red"><f:message key="${servicecheck.isActive}"/></td>
                             <td><s:link class="button" beanclass="cz.muni.fi.pa165.carparkweb.actionbeans.ServiceCheckActionBean" event="cancelCheck"><s:param name="servicecheck.id" value="${servicecheck.id}"/><f:message key="serviceCheck.cancelCheck"/></s:link></td>
                         </c:if>
                         <c:if test="${!servicecheck.isActive}">
                              <td><f:message key="${servicecheck.isActive}"/></td>
                              <td><s:link class="button" beanclass="cz.muni.fi.pa165.carparkweb.actionbeans.ServiceCheckActionBean" event="edit"><s:param name="servicecheck.id" value="${servicecheck.id}"/><f:message key="edit"/></s:link></td>
                         </c:if>                     
                        <td><s:link class="button" beanclass="cz.muni.fi.pa165.carparkweb.actionbeans.ServiceCheckActionBean" event="delete"><s:param name="servicecheck.id" value="${servicecheck.id}"/><f:message key="delete"/></s:link></td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>    
                    <br>
        <s:link class="button" beanclass="cz.muni.fi.pa165.carparkweb.actionbeans.ServiceCheckActionBean" event="add"><f:message key="serviceCheck.create"/></s:link>
    </s:layout-component>
</s:layout-render>
